<?php
$class = $this->uri->segment(1);

if ($next_page == '#') {
    $next_button = $next_page;
} else {
    $next_button = base_url() . $class . "/read_manga/" . $manga_id . "/" . $next_page;
}

if ($prev_page == "#") {
    $prev_button = $prev_page;
} else {
    $prev_button = base_url() . $class . "/read_manga/" . $manga_id . "/" . $prev_page;
}

$page_to_display = $page_content->row(0)->full_path;
?>

<script type="text/javascript">
    $(document).ready(function(){
        $("#all_chars").dialog({
            height: 300,
            width: 212,
            autoOpen: false,
            modal: true,
            resizable: false,
            show: "clip",
            title: "You are..."
        });
                
        $("#show_chars").click(function(){
            $("#all_chars").dialog("open");
            return false;
        });
    });
            
    $(document).keydown(function (e) {
        var keyCode = e.keyCode || e.which,
        arrow = {left: 37, up: 38, right: 39, down: 40 };

        switch (keyCode) {
            case arrow.left:
                window.location.replace('<?php echo $prev_button; ?>');
                return false;
            case arrow.right:
                window.location.replace('<?php echo $next_button; ?>');
                return false;
            }
        });
</script>



<div id="page_wrap">
    <?php
    $img_properties = array(
        'src' => base_url() . $page_to_display,
        'alt' => ''
    );

    $image = img($img_properties);
    ?>

    <a href="<?php echo $next_button; ?>"><?php echo $image; ?></a>

    <div id="navigation">
        <a class="nav_btn" href="<?php echo $prev_button; ?>"><< Back</a>
        <?php echo "Page " . $current_page . '/' . $total_page; ?>
        <a class="nav_btn" href="<?php echo $next_button; ?>">Next >></a>
    </div>

    <?php
    echo anchor($class, 'Back to reading list');
    ?>
</div>

<?php if ($next_page == '#'): ?>

    <div class="end_msg">
        You reach the end of the manga! <a id="show_chars" href="#">Which</a> character represents you?
    </div>
    <div id="all_chars">

        <?php foreach ($all_characters->result() as $character): ?>

            <div class="char_box">
                <?php
                $img_properties = array(
                    'src' => base_url() . $character->full_path,
                    'alt' => ''
                );
                $img_src = img($img_properties);
                $class_name = $this->uri->segment(1);
                $link_to = $class_name . '/choose_character/' . $character->character_id;

                echo anchor($link_to, $img_src);

                echo "<p>" . $character->name . "</p>";
                ?>

            </div>

        <?php endforeach; ?>
    </div>

<?php endif; ?>

